package com.mashang.bookkeepingbook.mapper;

import com.mashang.bookkeepingbook.pojo.AlterBillDTO;
import com.mashang.bookkeepingbook.pojo.BIllVo;
import com.mashang.bookkeepingbook.pojo.entity.Bill;
import com.mashang.bookkeepingbook.pojo.BillMonthlyListObject;
import com.mashang.bookkeepingbook.pojo.entity.Data;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface BillMapper {
    @Select("select * from bill where bill_id = #{billId}")
    Bill selectById(Integer billId) ;

    @Select("insert into bill (user_id,category_id,remark,bill_time,amount,type,create_time)values (#{userId},#{categoryId},#{remark},#{billTime},#{amount},#{type},#{createTime}) ")
    void insert(Bill bill);


    List<Data> select(@Param("userId") Integer userId, @Param("yearMonth") String yearmonth, @Param("categoryId") Integer categoryId);

    double selectExpenses(@Param("userId") Integer userId, @Param("year") String year, @Param("month") String month, @Param("categoryId") Integer categoryId);

    double selectIncome(@Param("userId") Integer userId, @Param("year") String year, @Param("month") String month, @Param("categoryId") Integer categoryId);

    @Update("update bill set amount = #{amount},bill_time = #{billTime},category_id = #{categoryId},remark = #{remark},type = #{type} where bill_id = #{billId}")
    void update(AlterBillDTO alterBillDTO);

    @Delete("delete from bill where bill_id = #{billId}")
    void deleteById(Integer billId);
    List<BillMonthlyListObject> selectAmountGroupByName(@Param("type") String type,@Param("userId") Integer userId,@Param("year") String year,@Param("month") String month);
}
